﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using HandyControl.Controls;
using MyHelper;

namespace weighing
{
    /// <summary>
    /// BillSettingWindow.xaml 的交互逻辑
    /// </summary>
    public partial class ImgSettingWindow : GlowWindow
    {


        public ImgSettingWindow()
        {
            InitializeComponent();
            CommonFunction.ShowCustomIcon(this);
        }
        private void GlowWindow_Loaded(object sender, RoutedEventArgs e)
        {

        }
        private void GlowWindow_ContentRendered(object sender, EventArgs e)
        {
            SetViewValue();
        }

        private void SaveBtn_Click(object sender, RoutedEventArgs e)
        {
            var path = this.pathTb.Text;

            if (!FileHelper.FolderExistsCreater(path))
            {
                Growl.Error("文件保存的位置不存在,创建不成功", "main");
                return;
            }
            App.Config.ImgConfig.CapturePath = path;
            int res = 0;



            App.Config.ImgConfig.OosType = OosType.Local;
            //不开启 不上传摄像机 过磅截图
            res = CommonFunction.UpdateAppConfig(nameof(ImgConfig));

            if (res < 0)
            {
                //验证输入不通过 ,不处理。
                this.saveBtn.IsChecked = false;
                return;
            }
            else if (res > 0)
            {
                Growl.Success("修改成功,重启后生效。", "main");
            }
            else
            {
                Growl.Error("修改失败！", "main");
            }
            this.Close();
        }
        /// <summary>
        /// 保存阿里云OOS
        /// </summary>
        /// <returns> >0 成功 </returns>

        /// <summary>
        ///TODO 七牛云对像 保存配制
        /// </summary>
        /// <returns></returns>
        private int SaveQiNiuYunConfig()
        {
            return 0;
        }

        /// <summary>
        ///TODO 奔牛云对像 保存配制
        /// </summary>
        /// <returns></returns>
        private int SaveBengNiuYunConfig()
        {
            return 0;
        }


        /// <summary>
        /// 设置界面上的 值
        /// </summary>
        private void SetViewValue()
        {
            string path = UrlHelper.Decode(App.Config.ImgConfig.CapturePath);
            if (path.IsNullOrEmpty())
            {
                path = Constant.DefaultImagePath;
            }
            this.pathTb.Text = path;
            switch (App.Config.ImgConfig.OosType)
            {
                case OosType.Local:
                    this.LocalRb.IsChecked = true;
                    break;
                default:
                    this.LocalRb.IsChecked = true;
                    break;
            }
        }

    }
}
